package com.mriassl.rabbitmq.base;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class BaseConnection {
	
	protected Connection conn;
	protected Channel channel;
	
	protected void init() throws IOException, TimeoutException{
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost(BaseConsts.RABBITMQ_HOST);
		factory.setUsername("clkj");
	    factory.setPassword("clkj123");
	    factory.setVirtualHost("clkj");
	    factory.setPort(5670);
		conn = factory.newConnection();
		channel = conn.createChannel();
	}
	
	protected void close() throws IOException, TimeoutException{
		if(channel != null){
			channel.close();
		}
		if(conn != null){
			conn.close();
		}
	}
	
}
